package com.example.sopenglandroidrenderer;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;

import com.example.openglandroidrenderer.OpenGLEngine;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "OpenGL_Android_Demo";

    OpenGLEngine engine = null; // OpenGL引擎

    private SurfaceView local_View;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.btn_init).setOnClickListener(this);
        findViewById(R.id.btn_uninit).setOnClickListener(this);
        findViewById(R.id.btn_open).setOnClickListener(this);
        findViewById(R.id.btn_close).setOnClickListener(this);

        local_View = findViewById(R.id.localview);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_init) {// 初始化
            init();
        } else if (view.getId() == R.id.btn_uninit) {// 反初始化
            uninit();
        } else if (view.getId() == R.id.btn_open) {// 打开相机
            openCam();
        } else if (view.getId() == R.id.btn_close) {// 关闭相机
            closeCam();
        }
    }

    public void init() {
        Log.d(TAG, "init");
        if (engine == null) {
            engine = OpenGLEngine.getInstance(getApplicationContext());
        }
    }

    public void uninit() {
        Log.d(TAG, "uninit");
    }

    public void openCam() {
        Log.d(TAG, "open Camera");
    }

    public void closeCam() {
        Log.d(TAG, "close Camera");
    }
}